//   MVCWin32 (Application.cpp)
//
//   Copyright 2010 Eric Llewellyn
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

#include "Application.h"

#include <windows.h>

namespace MVCWin32
{
	int Application::windowCount = 0;

	void Application::IncWindowCount()
	{
		windowCount++;
	}

	void Application::DecWindowCount()
	{
		windowCount--;
	}

	Application::Application()
	{
		this->delegatePtr=0;
	}

	int Application::Run()
	{
		if(delegatePtr !=0)
			delegatePtr->Loaded();
		MSG msg;
		while(GetMessage(&msg, NULL, 0, 0) != 0)
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			if(windowCount == 0 && delegatePtr !=0 && delegatePtr->QuitWhenNoWindows())
				this->Quit();
		}
		return msg.wParam;
	}
	
	void Application::Quit()
	{
		PostQuitMessage(0);
	}

	void Application::Init()
	{
	}
}